import { createRouter, createWebHistory } from "vue-router";

import Layout from "@/views/Layout/index.vue";
import Login from "@/views/Login/index.vue";
import Register from '@/views/Register/index.vue'
import Home from "@/views/Home/index.vue";
import Support from "@/views/Support/index.vue";
import Contact from "@/views/Contact/index.vue";
import Community from "@/views/Community/index.vue";
import Admin from "@/views/Admin/index.vue";

import UserInfo from "@/views/Admin/components/UserInfomation.vue";
import AdoptionApplication from "@/views/Admin/components/AdoptionApplication.vue";
import UserPost from "@/views/Admin/components/UserPost.vue";
import OrderManagement from "@/views/Admin/components/OrderManagement.vue";
import PostNewPet from "@/views/Admin/components/PostNewPet.vue"

import PetsList from "@/views/Pets/index.vue"
import PetsAll from "@/views/Pets/conponents/PetsAll.vue"
import PetsGoloden from "@/views/Pets/conponents/PetsGoloden.vue"
import PetsCatLi from "@/views/Pets/conponents/PetsCatLi.vue"
import PetsOther from "@/views/Pets/conponents/PetOther.vue"

import PetDetail from "@/views/PetDetail/index.vue"
import PetSearch from '@/views/PetSearch.vue'

import AboutUs from "@/views/Support/aboutUs.vue"
import Annouce from "@/views/Support/annouce.vue"
import  Donation  from '@/views/Support/donation.vue'

import PurchasedOrders from "@/views/Admin/components/orderManage/purchasedOrders.vue"
import SoldOrders from "@/views/Admin/components/orderManage/SoldOrders.vue"
import DisputeOrders from "@/views/Admin/components/orderManage/disputeOrders.vue"

import Article from "@/views/Community/article.vue"

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: "/login"  // 让未登录的用户重定向到登录页面
    },
    {
      path: "/login",
      component: Login
    },
    {
      path: "/register",
      component: Register
    },
    {
      path: "/",
      component: Layout,
      children: [
        { path: "home", component: Home },  // 首页
        // 宠物搜索页面
        { path: "pets/search", component: PetSearch },
        {
          path: "support",
          component: Support,
          children: [
            { path: "about", component: AboutUs },  // 支持我们
            { path: "annouce", component: Annouce },  // 公示
            { path: "donation", component: Donation}, // 捐款
          ]
        },
        { path: "contact", component: Contact },
        { path: "community", component: Community },
        // 个人中心
        {
          path: "admin",
          component: Admin,
          children: [
            { path: "user-info", component: UserInfo },
            { path: "adoption-application", component: AdoptionApplication },
            { path: "user-post", component: UserPost },
            { path: "order-management", component: OrderManagement },
            { path: "post-newpet", component: PostNewPet },
            { path: "purchased", component: PurchasedOrders }, // 我购买的
            { path: "sold", component: SoldOrders }, // 我卖出的
            { path: "dispute", component: DisputeOrders } // 争议订单
          ],
        },
        // 宠物列表
        {
          path: "pets-list",
          component: PetsList,
          children: [
            { path: "all", component: PetsAll },
            { path: "breed-jingmao", component: PetsGoloden },
            { path: "breed-lihua", component: PetsCatLi },
            { path: "breed-other", component: PetsOther },
          ]
        },
        // 宠物详情页面：id 为宠物 id
        { path: "petdetail/:id", component: PetDetail },
        // 文章页面
        { path: "article/:id", component: Article }
      ],
    },
  ]
});

export default router;
